<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>角色选择</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="角色,选择">
	<meta http-equiv="description" content="This is my page">

  </head>
  
  <body>
    <center>
    	<s:form name="frm" id="frm" method="post" action="queryRole.action" namespace="/inner/role/">
    		<jsp:include page="/jsp/outward/business/common/menuLink.jsp">
    			<jsp:param name="menuLink" value="[{'name':'角色选择'}]"/>
    			<jsp:param name="width" value="60%"/>
    		</jsp:include>
    		
    		<s:hidden name="actors" id="%{nodeType}Actors"></s:hidden>
    		<s:hidden name="nodeType" id="nodeType"></s:hidden>
    		
			<table cellspacing="0" width="100%">
				<tr>
					<td align="left">
						<input type="button" value="保存" class="btn" onclick="saveThis()"/>
					</td>
				</tr>
			</table>
    		
    		<table width="100%" cellspacing="1" cellpadding="3" bgcolor="#CCCCCC">
    			<tr class="tableHead" align="center">
    				<td width="10%">
    					
    				</td>
    				<td width="15%">
    					序号
    				</td>
    				<td width="30%">
    					类型
    				</td>
    				<td width="45%">
    					参与者名称
    				</td>
    			</tr>
    			<s:iterator value="list" status="s">
    				<tr align="center"
    					<s:if test="#s.index%2==0">class="tableRow2" onMouseMove="this.className='tableRow3'" onMouseOut="this.className='tableRow2'"</s:if>
						<s:else>class="tableRow1" onMouseMove="this.className='tableRow3'" onMouseOut="this.className='tableRow1'"</s:else>
    				>
    					<td>
    						<input type="checkbox" name="actorsIds" value="<s:property value='id'/>" actorsType="<s:property value='actorsType'/>" />
    					</td>
    					<td>
    						<s:property value="(pager.thisPage - 1) * pager.pageSize + #s.index + 1" />
    					</td>
    					<td>
    						<s:property value="actorsType"/>
    					</td>
    					<td>
    						<s:property value="actorsName"/>
    					</td>
    				</tr>
    			</s:iterator>
    		</table>
    	</s:form>
    </center>
    
    <script type="text/javascript">
	$(function(){
		initChecked();
	});

	function initChecked()
	{
		var nodeType = $('#nodeType');
		var actors = $('#' + nodeType.val() + 'Actors');
		if(!isNotNull(actors.val()))
			return;
		var actorAndType = actors.val().split(';');
		var len = actorAndType.length;
		for(var i = 0; i < len; i++)
		{
			var actorAndTypex = actorAndType[i];
			var actor = actorAndTypex.split('|')[0];
			var actorType = actorAndTypex.split('|')[1];
			var cb = $('input:checkbox[name="actorsIds"][value="' + actor + '"][actorsType="' + actorType + '"]');
			cb.attr('checked', true);
		}
	}
    
    function saveThis()
    {
    	var nodeType = $('#nodeType');
    	var actorsChecked = $('input:checkbox[name="actorsIds"][checked]');
    	var len = actorsChecked.length;
    	var returnValue = '';
    	for(var i = 0; i < len; i++)
    	{
			var actorx = $(actorsChecked.get(i));
			var actorId = actorx.val();
			var actorType = actorx.attr('actorsType');
			var actorAndType = actorId + '|' + actorType;
			returnValue += actorAndType;
			if(i < len - 1)
			{
				returnValue += ';';
			}
        }
        var actorsDiv = getParentWin().$('#' + nodeType.val() + 'ActorsDiv');
        if(isNotNull(returnValue))
        {
        	actorsDiv.text('已绑定');
        }
        else
        {
        	actorsDiv.text('未绑定');
        }
    	setReturnValue(returnValue);
    	window.close();
    }
    </script>
  </body>
</html>
